#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "equipment.h"
#include <QMainWindow>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QStyledItemDelegate>
#include <QMessageBox>
#include <QMap>
#include <QPair>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

enum COLUMN{
    _strength, _attack, _criticalProbability, _criticalValue,_strengthBonus, _attackBonus,
    _skillDamageBonus, _damageBonus, _criticalDamageBonus, _extraDamageBonus, _elementExtraDamageBonus,
    _elementAttributeBonus
};

class CenteredDelegate : public QStyledItemDelegate
{
public:
    CenteredDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent)
    {

    }
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        QStyleOptionViewItem opt = option;
        initStyleOption(&opt, index);

        // 设置文本对齐方式为居中
        opt.displayAlignment = Qt::AlignCenter;

        QStyledItemDelegate::paint(painter, opt, index);
    }
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    // 初始化界面
    void initSoftware();
    // 创建表头映射,方便操作对应行列
    void createHeaderMap();
    // 把各转职职业添加到combobox和qmap中
    void addCharacter();
    // 把人物属性填入表格中
    void addCharacterAttribute();
    // 计算相关伤害系数
    double computeAttackCoefficient(double value, double percent);
    double computeSTRorINTCoefficient(double value, double percent);
    double computeSkillDamageCoefficient(double percent);
    double computeCriticalStrikeCoefficient(double value, double probability, double damage);
    double computeExtraDamageCoefficient(double percent1, double percent2);
    double computeDamageIncreaseCoefficient(double percent);
    double computeElementAttributeCoefficient(double value);
    // 信息提示框
    void informationHint(QString info);
    // 没有json文件则创建一个
    void createJsonFile();
    // 读取装备信息json文件
    void readEquipmentJson();

signals:

public slots:
    // 计算基础伤害和最终伤害
    double computeBaseDamage();
    void computeFinalDamage();
    // 选择角色对应防具精通
    void armorMasteryOfCareer();
    // 获取装备数值
    QList<int> readEquipmentValue(QString equipmentType, QString equipmentName);
    // 更新表格数据
    void updateFormValue();
    // 切换职业或切换防具类型时读取对应装备信息
    void readWeponAndArmorInfo();
    // 切换强化等级时变更对应属性数值
    void changeReinforcementLevel();

private:
    const QMap<int,QString>HorizontalHeaderMap{
        {_strength,"力量/智力"},{_attack,"物攻/魔攻"},{_criticalProbability,"暴击率"},
        {_criticalValue,"暴击值"},{_strengthBonus,"力智加成"},{_attackBonus,"双攻加成"},
        {_skillDamageBonus,"技攻加成"},{_damageBonus,"黄字加成"},{_criticalDamageBonus,"暴伤加成"},
        {_extraDamageBonus,"白字加成"},{_elementExtraDamageBonus,"属白加成"},
        {_elementAttributeBonus,"属性强化"}
    };
    const QMap<int,QString>VerticalHeaderMap{
        {0,"人物属性"},{1,"武器"},{2,"防具套装"},{3,"首饰套装"},{4,"辅助装备"},{5,"面板数值"}
    };

    Ui::MainWindow *ui;
    QStandardItemModel *mw_model;
    bool mw_isNumber; // 判断表格内容是否为整数
    AddEquip *mw_addEquip;
    // 属性变量
    int strength;
    int baseAttack; // 人物基础攻击
    int attack;
    int criticalProbability;
    int criticalValue;
    int strengthBonus;
    int attackBonus;
    int skillDamageBonus;
    int damageBonus;
    int criticalDamageBonus;
    int extraDamageBonus;
    int elementExtraDamageBonus;
    int elementAttributeBonus;
    // 表格属性名称
    const QString _STR = tr("力量");
    const QString _INT = tr("智力");
    const QString _STRB = tr("力量加成");
    const QString _INTB = tr("智力加成");
    const QString _PATK = tr("物理攻击力");
    const QString _MATK = tr("魔法攻击力");
    const QString _PATKB = tr("物攻加成");
    const QString _MATKB = tr("魔攻加成");
    const QString _PCRIP = tr("物理暴击率");
    const QString _MCRIP = tr("魔法暴击率");
    const QString _PCRIV = tr("物理暴击");
    const QString _MCRIV = tr("魔法暴击");
    const QString _SKIB = tr("技能攻击");
    const QString _DAMB = tr("黄字");
    const QString _CRIDAMB = tr("暴伤");
    const QString _EXTDAMB = tr("白字");
    const QString _ELEEXTDAMB = tr("属白");
    const QString _ELEB = tr("属性强化");

};

class EquipmentInfo
{
public:
    // 属性变量
    int strength;
    int attack;
    int criticalProbability;
    int criticalValue;
    int strengthBonus;
    int attackBonus;
    int skillDamageBonus;
    int damageBonus;
    int criticalDamageBonus;
    int extraDamageBonus;
    int elementExtraDamageBonus;
    int elementAttributeBonus;
    double finalDamge;
};

#endif // MAINWINDOW_H
